package com.neusoft.yiyang.auth.service.impl;

import com.neusoft.yiyang.auth.service.CaptchaService;
import com.neusoft.yiyang.auth.util.CaptchaGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.image.BufferedImage;

/**
 * 图形验证码服务实现类
 */
@Service
public class CaptchaServiceImpl implements CaptchaService {

    private final CaptchaGenerator captchaGenerator;

    @Autowired
    public CaptchaServiceImpl(CaptchaGenerator captchaGenerator) {
        this.captchaGenerator = captchaGenerator;
    }

    @Override
    public String generateCaptchaText() {
        return captchaGenerator.generateText();
    }

    @Override
    public BufferedImage generateCaptchaImage(String captchaText) {
        return captchaGenerator.generateImage(captchaText);
    }

    @Override
    public boolean validateCaptcha(String inputCaptcha, String storedCaptcha) {
        return inputCaptcha != null && inputCaptcha.equalsIgnoreCase(storedCaptcha);
    }
}
